#include <iostream>
#include <fstream>

int main()
{
    std::string pathToDestIfcfgFromRamRoot = "ifcfg-eth0";
 
    std::ifstream ifs(pathToDestIfcfgFromRamRoot.c_str());
    if (ifs.is_open())
    {
        std::string writeBackLines;
        std::string line;
        bool foundFunctionEnd=false;
        bool foundFunctionBegin=false;
        while (getline(ifs, line, '\n'))
        {
            if (line.find("check_link_down") != std::string::npos)
            {
                foundFunctionBegin = true;
                if (line.find("}") != std::string::npos)
                {
                    foundFunctionEnd = true;
                    foundFunctionBegin = false;
                }
                else
                {
                    foundFunctionEnd = false;
                }
                continue;
            }
            //handle the check_link_down has multiple lines.
            if (foundFunctionBegin && !foundFunctionEnd)
            {
                if (line.find("}") != std::string::npos)
                {
                    foundFunctionEnd = true;
                    foundFunctionBegin = false;
                }
                else
                {
                    foundFunctionEnd = false;
                }
                continue;
            }
            
            writeBackLines.append(line);
            writeBackLines.append("\n");
        }
        ifs.close();        
        
        std::ofstream ofs(pathToDestIfcfgFromRamRoot.c_str());
        ofs << writeBackLines;
        ofs.close();
    }
}
